/**
	This code reserver for www.bookapon only. No any copy 
**/
var BookClass = Class.create({
	initialize: function (bookName,aWidth,aHeight,aArray,aPageTexture,aBookBinder,aBookBackground,aPageR,BorderLine,PagesCount)
	{	
		document.write("<br><br><br>");
		document.write("<div id ='"+bookName+"myIndex'></div>");
		document.write("<div id ='"+bookName+"'></div>");
		document.write("<br><br><br>");
		this.myBook = document.getElementById(bookName);
		this.myTab = document.getElementById(bookName+"myIndex");
		this.BookName = bookName;
		
		//this.myBook = document.getElementById("myBook");
		this.pWidth =  aWidth;
		this.pHeight =  aHeight;
		this.pageArray  = aArray; // non-used 
		this.PageTexture = aPageTexture;
		this.DataArray ;
		this.showBinder=true; //change to false for no binder
		this.binderImage = aBookBinder; //location of center binder
		this.backgroundImage = aBookBackground;
		this.BinderWidth = 20; //width of center binder image
		this.ShadowPicR = aPageR;
		this.iBorderLine = BorderLine;
		this.PageCount = PagesCount;
		
		var hideDiv,revealDiv,revealHtmlDiv,hideHtmlDiv,BorderDiv,BorderDiv2,PageshadowL,PageshadowR;
		
		this.isDrag = false;
		this.LeftBorder = 0;
		this.oElem;
		this.numPixels = 20; //number of pixels to slide per move
		
		this.leftStart=0;
		this.rightStart=1;
		this.currentPage = 0;
		this.IsAutoFlip =false;
		this.IsDoubleFlip = false;
		this.AutoflipPage= 0;
		this.IsDisable = false;
		this.IsDataArraySet = false;
		this.IsLoadPageSet = true;
		this.TabCount = 0;
		
		this.pageBorderColor="#000000"; //border color
		this.pageBorderStyle="solid"; //border style eg. solid, dashed or dotted.
		this.pSpeed=20; //page speed, 20 is best for Opera browser. Less is faster
		this.BrowserDef ;
		var myBinder;
		var myBackground;
		var isMoving=false;
		
		var Book ;
		this.BookIndex ;
		
		this.IsPageLoadArray = new Array();
		// Add for contain Genesis Object
		this.bookGenesisContainer = new Array(); 
	},
	
	Create:function()
	{	

		if(!document.getElementById(this.BookName) ){return;}; 

		this.myBook.style.width=(this.pWidth*2)+'px';
		this.myBook.style.height=this.pHeight+'px';
		this.myBook.style.position="relative";

	
		this.myTab.style.height = "40px";
		this.myTab.style.width = "100%";
		this.myTab.style.color ="white";
		this.myTab.style.width ="900px";
		this.myTab.style.position="relative";
		this.myTab.style.overflow = "hidden";
		this.myTab.style.zIndex="10";  
		
		// Create BookGenesisContainer
		
		for(var i = 0; i< this.PageCount;i++)
		{
			this.bookGenesisContainer[i] = new Array(); // Keep all Genesis for specific page 1	
			this.bookGenesisContainer[i][0] = new Genesis(0,0);
			this.bookGenesisContainer[i][0].setSize(this.pWidth,this.pHeight);
			this.bookGenesisContainer[i][0].getDomObj().id                = this.BookName+"flipHtml"+i;
			this.bookGenesisContainer[i][0].getDomObj().position		  =  "absolute";
			this.bookGenesisContainer[i][0].getDomObj().style.top         = "0px";
			this.bookGenesisContainer[i][0].getDomObj().style.left 		  = "0px";
			this.bookGenesisContainer[i][0].getDomObj().style.overflow    = "hidden";
			this.bookGenesisContainer[i][0].getDomObj().style.borderWidth = "0px";
			this.bookGenesisContainer[i][0].getDomObj().style.borderColor = this.pageBorderColor;
			this.bookGenesisContainer[i][0].getDomObj().style.borderStyle = this.pageBorderStyle;
			this.bookGenesisContainer[i][0].getDomObj().style.background  = "#785165 url('"+this.PageTexture+"') ";
			
			this.IsPageLoadArray[i] =false;
		}
		for(var i = 0; i< /*extArray.length*/ 4;i++)
		{
			var deg2radians = Math.PI * 2 / 360;
			var	deg = 30;
			var rad = deg * deg2radians ;
			costheta = Math.cos(rad);
			sintheta = Math.sin(rad);
			sinminus = -sintheta;
		
			// Tag Book Page
			var ImgDiv = document.createElement('div');
			ImgDiv.setAttribute("id",this.BookName+"flipHtml"+i);	
			ImgDiv.style.position="absolute";
			ImgDiv.style.width=this.pWidth+"px";
			ImgDiv.style.height=this.pHeight+"px";
			ImgDiv.style.top="0px";
			ImgDiv.style.left="0px";		
			ImgDiv.style.overflow="hidden";			
			//ImgDiv.style.borderWidth="1px";
			//ImgDiv.style.borderColor=this.pageBorderColor;
			//ImgDiv.style.borderStyle=this.pageBorderStyle;
			//ImgDiv.style.background="#785165 url('"+this.pageArray[i]+"') ";
			ImgDiv.style.background = "#785165 url('"+this.PageTexture+"')";
			//ImgDiv.style.background="#785165 url('Pic/Pictest.png') ";

			var myDiv = document.createElement('div'); 
				myDiv.setAttribute("id",this.BookName+"flipPage"+i);
				myDiv.style.position="absolute";
				myDiv.style.left=this.pWidth+this.LeftBorder+'px';
				myDiv.style.top=0+'px';
				myDiv.style.width=this.pWidth+"px";
				myDiv.style.height=this.pHeight+"px";			
				myDiv.style.overflow="hidden";
				myDiv.style.zIndex=this.PageCount-i;

			if(i%2 == 0)
			{	

				
				if(this.BookIndex == 1)
				{
				ImgDiv.onmousedown = function(e){BookArr[BookObjCount].dragBegin(e,true);};
				}
				else if(this.BookIndex == 2)
				{
				ImgDiv.onmousedown = function(e){BookArr[BookObjCount+1].dragBegin(e,true);};
				}
				else if(this.BookIndex == 3)
				{
				ImgDiv.onmousedown = function(e){BookArr[BookObjCount+2].dragBegin(e,true);};
				}
				else if(this.BookIndex == 4)
				{
				ImgDiv.onmousedown = function(e){BookArr[BookObjCount+3].dragBegin(e,true);};
				}
				else 
				{
				ImgDiv.onmousedown = function(e){BookArr[BookObjCount+4].dragBegin(e,true);};
				}
				
		
			}
			else
			{	
				
				if(this.BookIndex == 1)
				{
				ImgDiv.onmousedown = function(e){BookArr[BookObjCount].dragBegin(e,false);};
				}
				else if(this.BookIndex == 2)
				{
				ImgDiv.onmousedown = function(e){BookArr[BookObjCount+1].dragBegin(e,false);};
				}
				else if(this.BookIndex == 3)
				{
				ImgDiv.onmousedown = function(e){BookArr[BookObjCount+2].dragBegin(e,false);};
				}
				else if(this.BookIndex == 4)
				{
				ImgDiv.onmousedown = function(e){BookArr[BookObjCount+3].dragBegin(e,false);};
				}
				else
				{
				ImgDiv.onmousedown = function(e){BookArr[BookObjCount+4].dragBegin(e,false);};
				}
	
			}
			myDiv.appendChild(ImgDiv);
			this.myBook.appendChild(myDiv);
		}
		var LeftDiv = document.createElement('div');
			LeftDiv.setAttribute("id",this.BookName+"LeftBg");	
			LeftDiv.style.position="absolute";
			LeftDiv.style.width=0+"px";
			LeftDiv.style.height=this.pHeight+"px";
			LeftDiv.style.top="0px";
			LeftDiv.style.left="0px";		
			LeftDiv.style.overflow="hidden";			
			LeftDiv.style.background="#785165 url('"+this.PageTexture+"') ";
			LeftDiv.style.zIndex=1;
			this.myBook.appendChild(LeftDiv);
		
		var RightDiv = document.createElement('div');
			RightDiv.setAttribute("id",this.BookName+"RightBg");	
			RightDiv.style.position="absolute";
			RightDiv.style.width=0+"px";
			RightDiv.style.height=this.pHeight+"px";
			RightDiv.style.top="0px";
			RightDiv.style.left=this.pWidth+"px";		
			RightDiv.style.overflow="hidden";			
			RightDiv.style.background="#785165 url('"+this.PageTexture+"') ";
			RightDiv.style.zIndex=1;
			this.myBook.appendChild(RightDiv);
		
		if(this.showBinder)
		{
			myBinder = document.createElement('div'); 	
			myBinder.style.width=this.BinderWidth+"px";
			myBinder.style.height=this.pHeight+'px';
			myBinder.style.position="absolute";
			myBinder.style.top="0px";
			myBinder.style.left=this.pWidth-(this.BinderWidth/2)+"px";
			myBinder.style.background="transparent url('"+this.binderImage+"') top left repeat-y";
			myBinder.style.zIndex="50";
			this.myBook.appendChild(myBinder);		
		}
		
		myBackground = document.createElement('div'); 	
		myBackground.style.width=1000+"px";
		myBackground.style.height=600+'px';
		myBackground.style.position="absolute";
		myBackground.style.top="-20px";
		myBackground.style.left=-50+"px";
		myBackground.style.background="transparent url('"+this.backgroundImage+"') ";
		myBackground.style.zIndex="0";
		this.myBook.appendChild(myBackground);		
			
		PageshadowL = document.createElement('div'); 	
		PageshadowL.setAttribute("id",this.BookName+"PageshadowL");		
		PageshadowL.style.height=this.pHeight+'px';
		PageshadowL.style.position="absolute";
		PageshadowL.style.width=0+"px";
		PageshadowL.style.top="0px";
		PageshadowL.style.left=0+'px';
		PageshadowL.style.background="transparent url('"+this.ShadowPicR+"') top left repeat-y";
		PageshadowL.style.zIndex="50";
		//Pageshadow.style.FILTER = " alpha(opacity=50)";
		//PageshadowL.style.opacity = "0.5";
		this.myBook.appendChild(PageshadowL);
		
		PageshadowR = document.createElement('div'); 
		PageshadowR.setAttribute("id",this.BookName+"PageshadowR");		
		PageshadowR.style.height=this.pHeight+'px';
		PageshadowR.style.position="absolute";
		PageshadowR.style.width=0+"px";
		PageshadowR.style.top="0px";
		PageshadowR.style.left=this.pWidth+'px';
		PageshadowR.style.background="transparent url('"+this.ShadowPicR+"') top left repeat-y";
		PageshadowR.style.zIndex="50";
		//Pageshadow.style.FILTER = " alpha(opacity=50)";
		PageshadowR.style.opacity = "0.5";
		this.myBook.appendChild(PageshadowR);	
	
		BorderDiv = document.createElement('div');	
		BorderDiv.setAttribute("id",this.BookName+"BorderLine");
		BorderDiv.style.position="absolute";
		BorderDiv.style.width=0+"px";
		BorderDiv.style.height=this.pHeight+"px";
		BorderDiv.style.top="0px";
		BorderDiv.style.left=0+"px";		
		BorderDiv.style.overflow="hidden";	
		BorderDiv.style.background="#785165 url('"+this.iBorderLine+"') ";
		BorderDiv.style.zIndex=99;
		this.myBook.appendChild(BorderDiv);
		
		BorderDiv2 = document.createElement('div');
		BorderDiv2.setAttribute("id",this.BookName+"BorderLine2");	
		BorderDiv2.style.position="absolute";
		BorderDiv2.style.width=0+"px";
		BorderDiv2.style.height=this.pHeight+"px";
		BorderDiv2.style.top="0px";
		BorderDiv2.style.left=0+"px";		
		BorderDiv2.style.overflow="hidden";			
		BorderDiv2.style.background="#785165 url('"+this.iBorderLine+"') ";
		BorderDiv2.style.zIndex=99;
		this.myBook.appendChild(BorderDiv2);
		this.BrowserDef = Book.getBrowser();
	
		Book.SetPage(true);
	},

	gotoPage:function(topage)
	{	
		if(this.currentPage==topage)return;
		Book = BookArr[this.BookIndex-1];
		if(!this.IsDisable) // Prevent from do flip while book is still disable
		{	
			if(this.IsDataArraySet)
			{
				Book.RemovePageComponent();
			}
			if((!this.IsAutoFlip)&&(topage!=this.currentPage))
			{
				this.IsAutoFlip =true;
				this.AutoflipPage =topage;
				
				if((topage== this.PageCount)&&(this.currentPage==0)) // FrontMost to BackMost
				{
				    this.IsDoubleFlip = true;
					Book.PageMovePerform(2,true,2);
				}
				else if((topage==0)&&(this.currentPage==this.PageCount))//  BackMost to FrontMost 
				{	
					this.IsDoubleFlip = true;
					Book.PageMovePerform(2,false,this.PageCount-2);
				}
				else
				{	
					if(Math.abs(topage)>Math.abs(this.currentPage)) //DragRight
					{	
						Book.goFwdTo(topage);
					}
					else // DragLeft
					{
						Book.goBackTo(topage);
					}
				 }
			 }
		 }
	},
	/*
		PageMovePerform  use when do autoflip from frontmost to backmost or backmost to frontmost only
		num = number of times to flip
	*/
	PageMovePerform:function (num,IsRight,topage)
	{
		if(num==1){this.IsDoubleFlip = false;};
		this.AutoflipPage = topage;
		if(IsRight)
		{	
			
			Book.goFwdTo(topage);
		}
		else
		{	
			
			Book.goBackTo(topage);
		}
		num--;
		var valuenext;
		if(topage ==2)
		{
			valuenext = this.PageCount;
		}
		else
		{
			valuenext = 0;
		}
		//window.setTimeout('Book.PageMovePerform('+num+','+IsRight+','+valuenext+')',1500);
	},
	/*
		goFwdTo : SetPage before performing the MoveFwdPerform opertion 
		called by page Index move
	*/
	goFwdTo:function(topage)
	{
		if($(this).isMoving)
		{
			alert('gonexterror1');
			return;
		};
		$(this).isMoving=true;
		
		// Set Page which visible while moving to be Blank page
		if(topage == this.PageCount) //go to last page
		{	
			this.currentPage = this.PageCount;
			this.leftStart=2;
			this.rightStart=3;		
			
			var PrevHtmlDiv = document.getElementById(this.BookName+"flipHtml"+1);
			PrevHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
		}
		else
		{	
			this.leftStart=0;
			this.rightStart=1;	
			var Value = $(this).rightStart+1
			if(this.currentPage!=0)
			{
				var LeftBgDiv   = document.getElementById(this.BookName+"LeftBg") ;
				LeftBgDiv.style.width=this.pWidth+"px";
			}
			var NextHtmlDiv = document.getElementById(this.BookName+"flipHtml"+Value);
			NextHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
		}
			
		hideDiv   = document.getElementById(this.BookName+"flipPage"+$(this).leftStart);
		hideHtmlDiv	= document.getElementById(this.BookName+"flipHtml"+$(this).leftStart);
		hideHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
		
		revealDiv = document.getElementById(this.BookName+"flipPage"+$(this).rightStart);
		revealHtmlDiv = document.getElementById(this.BookName+"flipHtml"+$(this).rightStart);
		revealHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
		
		PageshadowL = document.getElementById(this.BookName+"PageshadowL");
		BorderDiv = document.getElementById(this.BookName+"BorderLine");
		BorderDiv2 = document.getElementById(this.BookName+"BorderLine2");
		
		//---  New Page Organize Style--//
		revealHtmlDiv.style.left="0px";	
		hideHtmlDiv.style.left="0px";	
		////////////////////////////////////////////
		
		revealDiv.style.width="0px";
		revealDiv.style.left=this.pWidth*2+'px';
		revealDiv.style.zIndex=99;
		
		Book.MoveFwdPerform(this.pWidth*2,0);
	},
	/*////////////////////////////////////////////////////////
		MoveFwdPerform : Perform page moving animation forward page 
		called by 1. goFwdTo operation ( page select index case) 
		             2. DragRelease case ( page does not go to very end yet)
	////////////////////////////////////////////////////*/
	MoveFwdPerform:function(currLeft,currWidth)
	{
		if(currLeft <= this.numPixels*2)
		{
			window.clearTimeout();
			
			revealDiv.style.left=this.LeftBorder+'px';
			revealDiv.style.width=this.pWidth+'px';
			hideDiv.style.width = 0+'px';
			BorderDiv.style.width = "0px";	
			BorderDiv2.style.width = "0px";				
			PageshadowL.style.width = "0px";
			revealDiv.style.zIndex= this.rightStart ;

			var LeftBgDiv   = document.getElementById(this.BookName+"LeftBg") ;
			LeftBgDiv.style.width=0+"px";
			
			
			$(this).isDrag = false;		
			$(this).isMoving=false;
			
			if(this.IsAutoFlip)
			{
				this.currentPage = parseInt(this.AutoflipPage);
				this.AutoflipPage =0;
				if(this.IsDoubleFlip)
				{
					Book.PageMovePerform(1,true,this.PageCount);
				}
				else
				{
				this.IsAutoFlip =false;
				}
			}
			else
			{
				this.currentPage = this.currentPage +2;
			}
	
			Book.SetPage(true);
			
			return;
		}	

		currLeft=currLeft-($(this).numPixels*2);//2 * width reveal
		currWidth=currWidth+$(this).numPixels;
		
		revealDiv.style.left=currLeft+'px';
		revealDiv.style.width=currWidth+'px';
		hideWidth = currLeft-this.pWidth;	
		
		if(hideWidth>0)
		{
			hideDiv.style.width=hideWidth+'px';
		}
		else
		{
			hideDiv.style.width=0+'px';
		}
		
		if(parseInt(revealDiv.style.left)+parseInt(revealDiv.style.width)+3 >this.pWidth)
		{
			BorderDiv.style.left = parseInt(revealDiv.style.left)+parseInt(revealDiv.style.width)+3+"px";
			BorderDiv.style.width = "5px";
						
			BorderDiv2.style.left = parseInt(revealDiv.style.left)-3+"px";
			BorderDiv2.style.width = "3px";
			
			PageshadowL.style.zIndex=parseInt(hideDiv.style.zIndex)+1; 
			PageshadowL.style.left = parseInt(BorderDiv.style.left)+"px";
			PageshadowL.style.width= this.pWidth -parseInt(hideDiv.style.width )-parseInt(revealDiv.style.width )+"px";
			
			if(this.BrowserDef==1)//FireFox
			{
				PageshadowL.style.opacity =(this.pWidth - parseInt(PageshadowL.style.width)-this.LeftBorder)/1000  ;
				BorderDiv.style.opacity = 0.4;
				BorderDiv2.style.opacity = 0.4;
			}
			else
			{
				PageshadowL.style.filter = 'alpha(opacity=' + ((this.pWidth - parseInt(PageshadowL.style.width)-this.LeftBorder)/1000)*100 + ')';
				BorderDiv.style.filter = 'alpha(opacity=' + 40 + ')';
				BorderDiv2.style.filter = 'alpha(opacity=' + 40 + ')';
			}
		}
		else
		{
			PageshadowL.style.width= 0+"px";				
			BorderDiv.style.width = "0px";
			BorderDiv2.style.width = "0px";
		}

		 window.setTimeout('Book.MoveFwdPerform('+currLeft+','+currWidth+')',$(this).pSpeed);
	},
	/*///////////////////////////////////////////////////////////////
		MoveFwdPerformReverse : Perform page moving animation to currently page 
		called by   DragRelease case ( page does not go to very end yet and user doesnt drage more than 1/4 of page width)	            
	/////////////////////////////////////////////////////////////////*/
	MoveFwdPerformReverse:function(currLeft,currWidth)
	{
		if(currWidth <= this.numPixels)
		{
			
			window.clearTimeout();
			
			var LeftBgDiv   = document.getElementById(this.BookName+"LeftBg") ;
			LeftBgDiv.style.width=0+"px";
			
			if(this.currentPage==0)
			{
				revealDiv.style.left=this.pWidth+'px';
				revealDiv.style.width=0+'px';
				
				hideDiv.style.width = this.pWidth+'px';
			}
			else if(this.currentPage == this.PageCount-2)
			{
				revealDiv.style.left=this.pWidth+'px';
				revealDiv.style.width=0+'px';
				
				hideDiv.style.width = this.pWidth+'px';
			}
			else
			{
			
				revealDiv.style.left=this.LeftBorder+'px';
				revealDiv.style.width=this.pWidth+'px';
				
				hideDiv.style.width = 0+'px';
				
				revealDiv.style.zIndex= this.rightStart ;
			}
			BorderDiv.style.width = "0px";	
			BorderDiv2.style.width = "0px";					
			PageshadowL.style.width = "0px";
			Book.SetPage(true);
			
			$(this).isDrag = false;		
			$(this).isMoving=false;
			
			return;
		}
		currLeft=currLeft+($(this).numPixels*2);//2 * width reveal
		currWidth=currWidth-$(this).numPixels;
		
		revealDiv.style.left=currLeft+'px';
		revealDiv.style.width=currWidth+'px';

		hideWidth = currLeft-this.pWidth;	

		if(hideWidth>0)
		{
			hideDiv.style.width=hideWidth+'px';
		}
		else
		{
			hideDiv.style.width=0+'px';	
		}
		
		if(parseInt(revealDiv.style.left)+parseInt(revealDiv.style.width)+3 >this.pWidth)
		{
			BorderDiv.style.left = parseInt(revealDiv.style.left)+parseInt(revealDiv.style.width)+3+"px";
			BorderDiv.style.width = "5px";
			
			BorderDiv2.style.left = parseInt(revealDiv.style.left)-3+"px";
			BorderDiv2.style.width = "3px";
						
			PageshadowL.style.zIndex=parseInt(hideDiv.style.zIndex)+1; 
			PageshadowL.style.left = parseInt(BorderDiv.style.left)+"px";
			PageshadowL.style.width= this.pWidth -parseInt(hideDiv.style.width )-parseInt(revealDiv.style.width )+"px";
			
			if(this.BrowserDef==1)//FireFox
			{
				PageshadowL.style.opacity =(this.pWidth - parseInt(PageshadowL.style.width)-this.LeftBorder)/1000  ;
				BorderDiv.style.opacity = 0.4;
				BorderDiv2.style.opacity = 0.4;
			}
			else
			{
				PageshadowL.style.filter = 'alpha(opacity=' + ((this.pWidth - parseInt(PageshadowL.style.width)-this.LeftBorder)/1000)*100 + ')';
				BorderDiv.style.filter = 'alpha(opacity=' + 40 + ')';
				BorderDiv2.style.filter = 'alpha(opacity=' + 40 + ')';
			}
		}
		else
		{
			PageshadowL.style.width= 0+"px";				
			BorderDiv.style.width = "0px";
			BorderDiv2.style.width = "0px";
		}
		 window.setTimeout('Book.MoveFwdPerformReverse('+currLeft+','+currWidth+')',$(this).pSpeed);
	},
	
	/*/////////////////////////////////////////////////////////////////////
		goBackTo : SetPage before performing the MoveBackPerform opertion 
		called by page Index move
	//////////////////////////////////////////////////////////////////////*/
	goBackTo :function(topage){
		if($(this).isMoving)
		{
			alert('Error1');
			return;
		}
		
		isMoving=true;
		
		if(topage==0)
		{
			this.leftStart=0;
			this.rightStart=1;
		
			var NextHtmlDiv = document.getElementById(this.BookName+"flipHtml"+2);
			NextHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
		}
		else if(this.currentPage == this.PageCount)
		{
			var PrevHtmlDiv = document.getElementById(this.BookName+"flipHtml"+1);
			PrevHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
		}
		else
		{	
			$(this).rightStart = 3;
			$(this).leftStart = 2;
			var PrevHtmlDiv = document.getElementById(this.BookName+"flipHtml"+1);
			PrevHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
			var RightBgDiv   = document.getElementById(this.BookName+"RightBg") ;
			RightBgDiv.style.width=this.pWidth+"px";
		}

		hideDiv = document.getElementById(this.BookName+"flipPage"+$(this).rightStart);
		hideHtmlDiv	= document.getElementById(this.BookName+"flipHtml"+$(this).rightStart);
		hideHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
		
		revealDiv = document.getElementById(this.BookName+"flipPage"+$(this).leftStart);
		revealHtmlDiv = document.getElementById(this.BookName+"flipHtml"+$(this).leftStart);	
		revealHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
		
		PageshadowL = document.getElementById(this.BookName+"PageshadowL");
		BorderDiv = document.getElementById(this.BookName+"BorderLine");
		BorderDiv2 = document.getElementById(this.BookName+"BorderLine2");
		
		//---  New Page Organize Style--//
		hideHtmlDiv.style.left="";	
		hideHtmlDiv.style.right=0+'px';
		revealHtmlDiv.style.left="";	
		revealHtmlDiv.style.right=0 + 'px';
		////////////////////////////////////////////
			
		revealDiv.style.left="0px";	
		revealDiv.style.width="0px";
		revealDiv.style.zIndex=99;

		hideDiv.style.left="";
		hideDiv.style.right=this.pWidth+"px";
		
		Book.MoveBackPerform(0,0);
	},
	
	/*///////////////////////////////////////////////////////////////
		MoveBackPerform : Perform page moving animation backward page 
		called by 1. goBackTo operation ( page select index case) 
		             2. DragRelease case ( page does not go to very end yet)            
	/////////////////////////////////////////////////////////////////*/
	MoveBackPerform:function(currLeft,currWidth)
	{
		if(currLeft >=(this.pWidth-($(this).numPixels)))
		{
			window.clearTimeout();
			
			revealDiv.style.left=this.pWidth-this.LeftBorder+"px";
			revealDiv.style.width=this.pWidth+"px";
			
			hideDiv.style.width = 0+'px';

			revealDiv.style.zIndex=this.PageCount-this.leftStart ;
			
			var RightBgDiv   = document.getElementById(this.BookName+"RightBg") ;
			RightBgDiv.style.width=0+"px";
			PageshadowL.style.width="0px";      
			BorderDiv.style.width = "0px";
			BorderDiv2.style.width = "0px";
			
			$(this).isMoving=false;
			$(this).isDrag = false;
			
			if(this.IsAutoFlip)
			{
				this.currentPage = parseInt(this.AutoflipPage);
				this.AutoflipPage =0;
				if(this.IsDoubleFlip)
				{
					Book.PageMovePerform(1,false,0);
				}
				else
				{
				this.IsAutoFlip =false;
				}
			}
			else
			{
				if( this.currentPage == this.PageCount)
				{
					this.leftStart=this.leftStart-2;
					this.rightStart=this.rightStart-2;
				}
				this.currentPage = this.currentPage -2;
			}
		
			
			Book.SetPage(false);
			return;
		}
		else
		{
			currLeft=currLeft+$(this).numPixels;//1 * width reveal
			currWidth=currWidth+$(this).numPixels;
			
			revealDiv.style.width=currWidth+'px';	
			revealDiv.style.left=currLeft+'px';
			
			hideWidth = this.pWidth-currWidth;	

			if(hideWidth -$(this).numPixels >0)
			{
				hideDiv.style.width=hideWidth-$(this).numPixels+'px';
				
				PageshadowL.style.zIndex=parseInt(hideDiv.style.zIndex)+1; 
				PageshadowL.style.left = "0px";
				PageshadowL.style.width= this.pWidth -parseInt(hideDiv.style.width )+"px";

				BorderDiv.style.left = parseInt(revealDiv.style.left)-3+"px";
				BorderDiv.style.width = "5px";
				
				BorderDiv2.style.left = parseInt(revealDiv.style.left)+parseInt(revealDiv.style.width)+3+"px";
				BorderDiv2.style.width = "3px";
			
				if(this.BrowserDef==1)//FireFox
				{
					PageshadowL.style.opacity =(this.pWidth - parseInt(PageshadowL.style.width)-this.LeftBorder)/1000  ;
					BorderDiv.style.opacity = 0.4;
					BorderDiv2.style.opacity = 0.4;
				}
				else
				{
					PageshadowL.style.filter = 'alpha(opacity=' + ((this.pWidth - parseInt(PageshadowL.style.width)-this.LeftBorder)/1000)*100 + ')';
					BorderDiv.style.filter = 'alpha(opacity=' + 40 + ')';
					BorderDiv2.style.filter = 'alpha(opacity=' + 40 + ')';
				}
			
			}
			else
			{
				hideDiv.style.width=0+'px';
				BorderDiv.style.width = "0px";
				BorderDiv2.style.width = "0px";
			}	
			 window.setTimeout('Book.MoveBackPerform('+currLeft+','+currWidth+')',$(this).pSpeed);
		}
	},
	
	/*///////////////////////////////////////////////////////////////
		MoveBackPerformReverse : Perform page moving animation to currently page 
		called by  DragRelease case  ( page does not go to very end yet and user doesnt drage more than 1/4 of page width)	            
	/////////////////////////////////////////////////////////////////*/
	MoveBackPerformReverse:function(currLeft,currWidth)
	{	
		if(currLeft<=$(this).numPixels)
		{
			window.clearTimeout();
			
			var RightBgDiv   = document.getElementById(this.BookName+"RightBg") ;
			RightBgDiv.style.width=0+"px";
			BorderDiv.style.width = "0px";
			BorderDiv2.style.width = "0px";
			PageshadowL.style.width = "0px";
			if(this.currentPage-2==0)
			{
				revealDiv.style.left=this.LeftBorder+"px";
				revealDiv.style.width=0+"px";
				
				hideDiv.style.width = this.pWidth+'px';
			}
			else if(this.currentPage==this.PageCount)
			{
				revealDiv.style.left=this.pWidth-this.LeftBorder+"px";
				revealDiv.style.width=0+"px";
				
				hideDiv.style.width = this.pWidth+'px';
			}
			else
			{
				revealDiv.style.left=this.pWidth-this.LeftBorder+"px";
				revealDiv.style.width=this.pWidth+"px";
				
				hideDiv.style.width = 0+'px';
			}
			revealDiv.style.zIndex= this.PageCount-this.leftStart ;
			
			Book.SetPage(false);
			$(this).isMoving=false;
			$(this).isDrag = false;

			return;
		}
		else
		{
			currLeft=currLeft-$(this).numPixels;//1 * width reveal
			currWidth=currWidth-$(this).numPixels;
			
			revealDiv.style.width=currWidth+'px';	
			revealDiv.style.left=currLeft+'px';

			hideWidth = this.pWidth-currWidth;	

			if(hideWidth -$(this).numPixels >0)
			{
				hideDiv.style.width=hideWidth-$(this).numPixels+'px';
				
				PageshadowL.style.zIndex=parseInt(hideDiv.style.zIndex)+1; 
				PageshadowL.style.left = "0px";
				PageshadowL.style.width= this.pWidth -parseInt(hideDiv.style.width )+"px";
					
				BorderDiv.style.left = parseInt(revealDiv.style.left)-3+"px";
				BorderDiv.style.width = "5px";
				
				BorderDiv2.style.left = parseInt(revealDiv.style.left)+parseInt(revealDiv.style.width)+3+"px";
				BorderDiv2.style.width = "3px";
				
				if(this.BrowserDef==1)//FireFox
				{
					PageshadowL.style.opacity =(this.pWidth - parseInt(PageshadowL.style.width)-this.LeftBorder)/1000  ;
					BorderDiv.style.opacity = 0.4;
					BorderDiv2.style.opacity = 0.4;
				}
				else
				{
					PageshadowL.style.filter = 'alpha(opacity=' + ((this.pWidth - parseInt(PageshadowL.style.width)-this.LeftBorder)/1000)*100 + ')';
					BorderDiv.style.filter = 'alpha(opacity=' + 40 + ')';
					BorderDiv2.style.filter = 'alpha(opacity=' + 40 + ')';
				}
					
			}
			else
			{
				hideDiv.style.width=0+'px';
				BorderDiv.style.width = "0px";
				BorderDiv2.style.width = "0px";
			}	
			 window.setTimeout('Book.MoveBackPerformReverse('+currLeft+','+currWidth+')',$(this).pSpeed);
		}
	},

/////////////////////////////////////// THIS IS FOR DRAGGING FUNCTION//////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////
	/****************************************************
	* FUNCTION
	*		removeGenesisObj
	*
	* DESCRIPTION
	* 		Remove all Genesis Object form page when user want to change page.
	*
	* ARGUMENTS
	*
	****************************************************/
	removeGenesisObj:function()
	{
		// Remove Old tag div
		var pageLeft  = Book.getCurrentLeftPage();
		var pageRight = Book.getCurrentRightPage();
		if(pageLeft == 0 )
		{
			var  toppage    = document.getElementById(this.BookName+"flipHtml"+0);
			try
			{
				toppage.removeChild(this.bookGenesisContainer[0][0].getDomObj());
			}
			catch(error)
			{
				
			}
			//toppage.innerHTML = '';
		}
		else if(pageLeft == this.PageCount -1)
		{
			var  buttonpage = document.getElementById(this.BookName+"flipHtml"+3);
			try
			{
				buttonpage.removeChild(this.bookGenesisContainer[this.PageCount-1][0].getDomObj());
			}
			catch(error)
			{
				
			}
			//buttonpage.innerHTML = '';
		}
		else
		{
			var  templeft  = document.getElementById(this.BookName+"flipHtml"+1);
			var  tempright = document.getElementById(this.BookName+"flipHtml"+2);
			try
			{
				templeft.removeChild(this.bookGenesisContainer[this.currentPage-1][0].getDomObj());
				tempright.removeChild(this.bookGenesisContainer[this.currentPage][0].getDomObj());
			}
			catch(error)
			{
			
			}
			//templeft.innerHTML = '';
			//tempright.innerHTML = '';
		}
		
	},
	
	
	dragBegin:function(e,dir)
	{		
		Book = BookArr[this.BookIndex-1];
		this.removeGenesisObj();
		if(this.IsDataArraySet)
		{
		  Book.RemovePageComponent();
		}
		
		if($(this).isMoving||$(this).IsAutoFlip){return;}
		
		if(!$(this).isDrag)
		{
			isDrag = true;
			if(dir) // DragRight
			{
			// Set Page which visible while moving to be Blank page
			if(this.currentPage == this.PageCount-2)
			{
				this.leftStart=2;
				this.rightStart=3;		
				
				var LeftBgDiv   = document.getElementById(this.BookName+"LeftBg") ;
				LeftBgDiv.style.width=this.pWidth+"px";
				
				//var PrevHtmlDiv = document.getElementById("flipHtml"+3);
				//PrevHtmlDiv.style.background="#785165 url('Pic/Pictest.png') ";
			}
			else if(this.currentPage ==0)
			{
				var Value = $(this).rightStart+1
				var NextHtmlDiv = document.getElementById(this.BookName+"flipHtml"+Value);
				NextHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
			}
			else
			{	
				$(this).leftStart = 0;
				$(this).rightStart = 1;
				var Value = $(this).rightStart+1
				
				var LeftBgDiv   = document.getElementById(this.BookName+"LeftBg") ;
				LeftBgDiv.style.width=this.pWidth+"px";
				var NextHtmlDiv = document.getElementById(this.BookName+"flipHtml"+Value);
				NextHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
			}
			
			
			$(this).oElem   = document.getElementById(this.BookName+"flipPage"+$(this).leftStart);

			hideDiv   = document.getElementById(this.BookName+"flipPage"+$(this).leftStart);
			hideHtmlDiv   = document.getElementById(this.BookName+"flipHtml"+$(this).leftStart);
			hideHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
			revealDiv = document.getElementById(this.BookName+"flipPage"+$(this).rightStart);
			revealHtmlDiv = document.getElementById(this.BookName+"flipHtml"+$(this).rightStart);
			revealHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
			
			PageshadowL = document.getElementById(this.BookName+"PageshadowL");
			BorderDiv = document.getElementById(this.BookName+"BorderLine");
			BorderDiv2 = document.getElementById(this.BookName+"BorderLine2");
			//---  New Page Organize Style--//
			revealHtmlDiv.style.left="0px";	
			hideHtmlDiv.style.left="0px";	
			////////////////////////////////////////////

			revealDiv.style.width="0px";
			revealDiv.style.left=this.pWidth*2+'px';
			revealDiv.style.zIndex=99;

			e = e ? e : window.event;
			$(this).oElem.mouseX = e.clientX;
			$(this).oElem.mouseY = e.clientY;
			
			document.onmousemove = function(e){Book.dragRight(e);};
			document.onmouseup = function(e){Book.dragRightEnd(e);};
			//document.onmouseup = function(e){dragEnd(e);};
			}
			else // DragLeft
			{
				if(this.currentPage-2==0)
				{
					this.leftStart=0;
					this.rightStart=1;
				
					var NextHtmlDiv = document.getElementById(this.BookName+"flipHtml"+2);
					NextHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
				}
				else if(this.currentPage == this.PageCount)
				{
					var PrevHtmlDiv = document.getElementById(this.BookName+"flipHtml"+1);
					PrevHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
				}
				else
				{	
					$(this).rightStart = 3;
					$(this).leftStart = 2;
					var PrevHtmlDiv = document.getElementById(this.BookName+"flipHtml"+1);
					PrevHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
					var RightBgDiv   = document.getElementById(this.BookName+"RightBg") ;
					RightBgDiv.style.width=this.pWidth+"px";
					//var NextHtmlDiv = document.getElementById("flipHtml"+4);
					//NextHtmlDiv.style.background="#785165 url('Pic/Pictest.png') ";
				}

				hideDiv = document.getElementById(this.BookName+"flipPage"+$(this).rightStart);
				hideHtmlDiv	= document.getElementById(this.BookName+"flipHtml"+$(this).rightStart);
				hideHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
				revealDiv = document.getElementById(this.BookName+"flipPage"+$(this).leftStart);
				revealHtmlDiv = document.getElementById(this.BookName+"flipHtml"+$(this).leftStart);	
				revealHtmlDiv.style.background="#785165 url('"+this.PageTexture+"') ";
				
				PageshadowL = document.getElementById(this.BookName+"PageshadowL");
				BorderDiv = document.getElementById(this.BookName+"BorderLine");
				BorderDiv2 = document.getElementById(this.BookName+"BorderLine2");
				//---  New Page Organize Style--//
				hideHtmlDiv.style.left="";	
				hideHtmlDiv.style.right=0+'px';
				revealHtmlDiv.style.left="";	
				revealHtmlDiv.style.right=0 + 'px';
				////////////////////////////////////////////
					
				revealDiv.style.left="0px";	
				revealDiv.style.width="0px";
				revealDiv.style.zIndex=99;

				hideDiv.style.left="";
				hideDiv.style.right=this.pWidth+"px";
			
				$(this).oElem   = document.getElementById(this.BookName+"flipPage"+$(this).rightStart);

				e = e ? e : window.event;
				$(this).oElem.mouseX = e.clientX;
				$(this).oElem.mouseY = e.clientY;

				document.onmousemove = function(e){Book.dragLeft(e);};
				document.onmouseup = function(e){Book.dragLeftEnd(e);};
				//document.onmouseup = function(e){dragEnd(e);};
			}
		}
	},

	dragLeft:function (e)
    {
		if(parseInt(revealDiv.style.left) >= this.pWidth -this.LeftBorder)
		{
			revealDiv.style.left=this.pWidth-this.LeftBorder+"px";
			revealDiv.style.width=this.pWidth+"px";
			hideDiv.style.width = "0px";
			revealDiv.style.zIndex=this.PageCount-this.leftStart ;
	
			if( this.currentPage ==this.PageCount)
			{
				this.leftStart=this.leftStart-2;
				this.rightStart=this.rightStart-2;
			
			}
			this.currentPage = this.currentPage -2;
			
			var RightBgDiv   = document.getElementById(this.BookName+"RightBg") ;
			RightBgDiv.style.width=0+"px";
			PageshadowL.style.width="0px";      

			this.BorderDiv.style.width = "0px";
			this.BorderDiv2.style.width = "0px";
			
			document.onmousemove = null;
			document.onmouseup = null; 
			
			Book.SetPage(false);
			$(this).isDrag = false;
			
			return;
	    }
		else
		{
			e = e ? e : window.event;
			if((e.clientX - $(this).oElem.mouseX)>0)
			{
				revealDiv.style.left = (1/2)*(e.clientX - $(this).oElem.mouseX)+this.LeftBorder   + 'px'; 
			
				revealDiv.style.width =  (1/2)*(e.clientX - $(this).oElem.mouseX) - this.LeftBorder  + 'px'; 
				
				if((this.pWidth - (e.clientX - $(this).oElem.mouseX)-this.LeftBorder)>0)
				{
				hideDiv.style.width =	this.pWidth - (e.clientX - $(this).oElem.mouseX)-this.LeftBorder  +'px';
				}
				PageshadowL.style.zIndex=parseInt(hideDiv.style.zIndex)+1; 
				PageshadowL.style.left = "0px";
				PageshadowL.style.width= this.pWidth -parseInt(hideDiv.style.width )+"px";
				
				BorderDiv.style.left = parseInt(revealDiv.style.left)-3+"px";
				BorderDiv.style.width = "5px";
				
				
				BorderDiv2.style.left = parseInt(revealDiv.style.left)+parseInt(revealDiv.style.width)+3+"px";
				BorderDiv2.style.width = "3px";
				
				if(this.BrowserDef==1)//FireFox
				{
					PageshadowL.style.opacity =(this.pWidth - parseInt(PageshadowL.style.width)-this.LeftBorder)/1000  ;
					BorderDiv.style.opacity = 0.4;
					BorderDiv2.style.opacity = 0.4;
				}
				else
				{
					PageshadowL.style.filter = 'alpha(opacity=' + ((this.pWidth - parseInt(PageshadowL.style.width)-this.LeftBorder)/1000)*100 + ')';
					BorderDiv.style.filter = 'alpha(opacity=' + 40 + ')';
					BorderDiv2.style.filter = 'alpha(opacity=' + 40 + ')';
				}
				
			}
			return false;
		}
	},
	dragRight:function(e)
	{
		if(parseInt(revealDiv.style.left) <= this.LeftBorder )
		{
			revealDiv.style.left=this.LeftBorder+'px';
			revealDiv.style.width=this.pWidth+'px';
			hideDiv.style.width = 0+'px';
			revealDiv.style.zIndex= this.rightStart ;
			
			var LeftBgDiv   = document.getElementById(this.BookName+"LeftBg") ;
			LeftBgDiv.style.width=0+"px";
			BorderDiv.style.width = "0px";
			BorderDiv2.style.width = "0px";
			this.currentPage = this.currentPage +2;
			Book.SetPage(true);
			
			this.isDrag = false;
			document.onmousemove = null;
			document.onmouseup = null;
			return false ;
	    }	
		else
		{
			e = e ? e : window.event;
			if(e.clientX - $(this).oElem.mouseX<0)
			{
				revealDiv.style.left =(  this.pWidth*2 + (e.clientX - $(this).oElem.mouseX) ) + 'px'; 
				revealDiv.style.width =  Math.abs(e.clientX - $(this).oElem.mouseX)*(1/2) + 'px';
				
				if((this.pWidth - Math.abs(e.clientX - $(this).oElem.mouseX))>0)//((revealLeft  - pWidth - this.LeftBorder)>0)
				{
					hideDiv.style.width =	this.pWidth - Math.abs(e.clientX - $(this).oElem.mouseX)+'px';
				}
				else
				{
					hideDiv.style.width =	0+'px';
				}
				if(parseInt(revealDiv.style.left)+parseInt(revealDiv.style.width)+3 >this.pWidth)
				{
					BorderDiv.style.left = parseInt(revealDiv.style.left)+parseInt(revealDiv.style.width)+3+"px";
					BorderDiv.style.width = "5px";
					
					BorderDiv2.style.left = parseInt(revealDiv.style.left)-3+"px";
					BorderDiv2.style.width = "3px";
					
					PageshadowL.style.zIndex=parseInt(hideDiv.style.zIndex)+1; 
					PageshadowL.style.left = parseInt(BorderDiv.style.left)+"px";
					PageshadowL.style.width= this.pWidth -parseInt(hideDiv.style.width )-parseInt(revealDiv.style.width )+"px";
					
					if(this.BrowserDef==1)//FireFox
					{
						PageshadowL.style.opacity =(this.pWidth - parseInt(PageshadowL.style.width)-this.LeftBorder)/1000  ;
						BorderDiv.style.opacity = 0.4;
						BorderDiv2.style.opacity = 0.4;
					}
					else
					{
						PageshadowL.style.filter = 'alpha(opacity=' + ((this.pWidth - parseInt(PageshadowL.style.width)-this.LeftBorder)/1000)*100 + ')';
						BorderDiv.style.filter = 'alpha(opacity=' + 40 + ')';
						BorderDiv2.style.filter = 'alpha(opacity=' + 40 + ')';
					}
					
				}
				else
				{
					BorderDiv.style.width = "0px";
					BorderDiv2.style.width = "0px";
				}
			}
		return false;
		}
		
	},
	dragLeftEnd:function (e)
    {
		document.onmousemove = null;
		document.onmouseup = null;
		$(this).isMoving = true;
		var Check = parseInt(revealDiv.style.left);
		if(Math.abs(Check)>Math.abs(($(this).pWidth)*(1/4)))
		{
			Book.MoveBackPerform(parseInt(revealDiv.style.left), parseInt(revealDiv.style.width));
		}
		else
		{
			Book.MoveBackPerformReverse(parseInt(revealDiv.style.left), parseInt(revealDiv.style.width));
		}			
		return false;
	},
	
	dragRightEnd:function (e)
    {
		document.onmousemove = null;
		document.onmouseup = null;
		$(this).isMoving = true;
		var Check = parseInt(revealDiv.style.left);
		
		if(Math.abs(Check)>Math.abs(($(this).pWidth)*(3/2)))
		{
			Book.MoveFwdPerformReverse(parseInt(revealDiv.style.left), parseInt(revealDiv.style.width));
		}
		else
		{
			Book.MoveFwdPerform(parseInt(revealDiv.style.left), parseInt(revealDiv.style.width));
		}
		//PageshadowR.style.width= "0px";
		return false;
	},
	
	dragEnd:function (e)
    {
		document.onmousemove = null;
		document.onmouseup = null;
		
		return false;
	},
	
	DisableMouseEvent:function ()
    {	
		for(var i = 0; i< 4;i++)
		{	
			var SampleDiv   = document.getElementById(this.BookName+"flipHtml"+i);

			if(i%2 == 0)
			{
				SampleDiv.onmousedown = null;
			}
			else
			{
				SampleDiv.onmousedown = null;
			}
		}
		
		this.IsDisable = true;
	},
	
	EnableMouseEvent:function (e)
    {	
		for(var i = 0; i< 4;i++)
		{
			SampleDiv   = document.getElementById(this.BookName+"flipHtml"+i);
			if(i%2 == 0)
			{
				SampleDiv.onmousedown = function(e){Book.dragBegin(e,true);};
			}
			else
			{
				SampleDiv.onmousedown = function(e){Book.dragBegin(e,false);};
			}
		}
		
		this.IsDisable = false;
	},
	
	getLastPage:function ()
    {
		return  this.PageCount-1;
	},
	
	getCurrentLeftPage:function()
	{
		if(this.currentPage-1>=0)
		return this.currentPage-1;
		else
		return this.currentPage;
	},
	
	getCurrentRightPage:function()
	{
		if(this.currentPage<this.PageCount-1)
		return this.currentPage;
		else
		return this.PageCount-1;
	},
	
	getBrowser:function ()
    {
		if (/MSIE (\d+\.\d+);/.test(navigator.userAgent))
		{
		var ieversion=new Number(RegExp.$1)
		return 0;
		}		
		else if (/Firefox[\/\s](\d+\.\d+)/.test(navigator.userAgent))
		{
		var ffversion=new Number(RegExp.$1)
		return 1;
		}
		else
		{
		return 2;
		}
	
	},
	SetPage:function(IsDragRight)
	{	
			if(this.currentPage ==0)
			{	
				var LeftHtmlDiv = document.getElementById(this.BookName+"flipHtml"+0);
				if(this.IsLoadPageSet)
				{				
				//LeftHtmlDiv.style.background="#785165 url('"+this.pageArray[0]+"')";
				LeftHtmlDiv.appendChild(this.bookGenesisContainer[0][0].getDomObj());
				}
				if(this.IsDataArraySet)
				{	
					var ComponentDiv = document.createElement('div');
					ComponentDiv.setAttribute("id",this.BookName+"Data"+0);	
					ComponentDiv.innerHTML = this.DataArray[0];
					LeftHtmlDiv.appendChild(ComponentDiv);
				}
			}
			else if(this.currentPage == this.PageCount)
			{	
				var LeftHtmlDiv = document.getElementById(this.BookName+"flipHtml"+3);	
				if(this.IsLoadPageSet)
				{
					//LeftHtmlDiv.style.background="#785165 url('"+this.pageArray[this.currentPage-1]+"')";
					LeftHtmlDiv.appendChild(this.bookGenesisContainer[this.currentPage-1][0].getDomObj());
				}
				if(this.IsDataArraySet)
				{	
					if(this.DataArray.length>this.currentPage-1)
					{
					var ComponentDiv = document.createElement('div');
					ComponentDiv.setAttribute("id",this.BookName+"Data"+3);	
					ComponentDiv.innerHTML = this.DataArray[this.currentPage-1];
					LeftHtmlDiv.appendChild(ComponentDiv);
					}
				}
			}
			else
			{	
				var LeftHtmlDiv = document.getElementById(this.BookName+"flipHtml"+1);	
				var RightHtmlDiv	= document.getElementById(this.BookName+"flipHtml"+2);
				if(this.IsLoadPageSet)
				{				
					//LeftHtmlDiv.style.background="#785165 url('"+this.pageArray[this.currentPage-1]+"')";
					LeftHtmlDiv.appendChild(this.bookGenesisContainer[this.currentPage-1][0].getDomObj());
							
					//RightHtmlDiv.style.background="#785165 url('"+this.pageArray[this.currentPage]+"') ";
					RightHtmlDiv.appendChild(this.bookGenesisContainer[this.currentPage][0].getDomObj());
				}
				if(this.IsDataArraySet)
				{
					if(this.DataArray.length>this.currentPage-1)
					{
					var ComponentDiv = document.createElement('div');
					ComponentDiv.setAttribute("id",this.BookName+"Data"+1);	
					ComponentDiv.innerHTML = this.DataArray[this.currentPage-1];
					LeftHtmlDiv.appendChild(ComponentDiv);
					}
					if(this.DataArray.length>this.currentPage)
					{
					var ComponentDiv1 = document.createElement('div');
					ComponentDiv1.setAttribute("id",this.BookName+"Data"+2);	
					ComponentDiv1.innerHTML = this.DataArray[this.currentPage];
					RightHtmlDiv.appendChild(ComponentDiv1);
					}
				}
			}
		if(this.IsLoadPageSet)
		{
		 //load page left
		loadPage(user_id,book_id,Book.getCurrentLeftPage());
		 //load page right
		loadPage(user_id,book_id,Book.getCurrentRightPage());
		}
				
	},
	SetDataArrayComponent:function(aDataArray)
	{
	
		this.DataArray = aDataArray;
		this.IsDataArraySet = true;
				
	},
	AddTabPanel:function(Name,Page)
	{
		var Index = document.getElementById(this.BookName+"myIndex");	
		var newIndex = document.createElement('A'); 
		
			if(this.BookIndex == 1)
				{
					newIndex.setAttribute("href","javascript:BookArr[BookObjCount].gotoPage('"+Page+"');"); 
				}
				else if(this.BookIndex == 2)
				{
					newIndex.setAttribute("href","javascript:BookArr[BookObjCount+1].gotoPage('"+Page+"');"); 
				}
				else if(this.BookIndex == 3)
				{
					newIndex.setAttribute("href","javascript:BookArr[BookObjCount+2].gotoPage('"+Page+"');"); 
				} 
				else if(this.BookIndex == 4)
				{
					newIndex.setAttribute("href","javascript:BookArr[BookObjCount+3].gotoPage('"+Page+"');"); 
				} 
				else
				{
					newIndex.setAttribute("href","javascript:BookArr[BookObjCount+4].gotoPage('"+Page+"');"); 
				} 
		newIndex.className = "BookTab";
		newIndex.style.left= 120+120*this.TabCount+'px';
		newIndex.style.background = "#785165 url('"+this.PageTexture+"')";
		newIndex.innerHTML = Name;
		this.TabCount++;
		Index.appendChild(newIndex);
		
	},
	AddPageIndexPanel:function()
	{
		for(var i = 0; i <= this.PageCount;i++)
		{	
			if(i%2 ==0)
			{
			var Index = document.getElementById(this.BookName+"myIndex");
			var newIndex = document.createElement('A'); 
			//newIndex.setAttribute("onClick","autoFlip('"+i+"');"); 
				if(this.BookIndex == 1)
				{
					newIndex.setAttribute("href","javascript:BookArr[BookObjCount].gotoPage('"+i+"');");
				}
				else if(this.BookIndex == 2)
				{
					newIndex.setAttribute("href","javascript:BookArr[BookObjCount+1].gotoPage('"+i+"');");
				}
				else if(this.BookIndex == 3)
				{
				newIndex.setAttribute("href","javascript:BookArr[BookObjCount+2].gotoPage('"+i+"');");
				}
				else if(this.BookIndex ==4)
				{
				newIndex.setAttribute("href","javascript:BookArr[BookObjCount+3].gotoPage('"+i+"');");
				}
				else
				{
				newIndex.setAttribute("href","javascript:BookArr[BookObjCount+4].gotoPage('"+i+"');");
				}
			newIndex.className = "BookTab";
			newIndex.style.width = "60px";
			newIndex.style.left= 60+60*this.TabCount+'px';
			newIndex.style.background = "#785165 url('"+this.PageTexture+"')";
			newIndex.innerHTML = "Page"+i;
			this.TabCount++;
			Index.appendChild(newIndex);

			}
		}
	
	},
	RemovePageComponent:function()
	{
		if(this.currentPage ==0)
		{
			var ComponentDiv = document.getElementById(this.BookName+"Data"+0);	
			ComponentDiv.parentNode.removeChild(ComponentDiv);
		}
		else if(this.currentPage == this.PageCount)
		{	
			if(this.DataArray.length>this.currentPage)
			{
			var ComponentDiv = document.getElementById(this.BookName+"Data"+3);	
			ComponentDiv.parentNode.removeChild(ComponentDiv);
			}
		}
		else
		{	
			if(this.DataArray.length>this.currentPage-1)
			{
			var ComponentDiv1 = document.getElementById(this.BookName+"Data"+1);	
			ComponentDiv1.parentNode.removeChild(ComponentDiv1);
			}
			if(this.DataArray.length>this.currentPage)
			{
			var ComponentDiv2 = document.getElementById(this.BookName+"Data"+2);	
			ComponentDiv2.parentNode.removeChild(ComponentDiv2);
			}
		}

	},
	DisableLoadFromDb:function()
	{
		this.IsLoadPageSet = false;
	
	},
	AddSelf:function(BookObj,Num)
	{	
		Book = BookObj;
		this.BookIndex = Num;
	}
	
});